﻿ //===============================RuinAlgorithm.cs==============================\\
//===Bart Steijlen======\\

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

namespace Team2_Vision
{
    class RuinCluster : VisionAlgorithm
    {
        public RuinCluster(String name) : base(name) { }
        public override System.Drawing.Bitmap DoAlgorithm(System.Drawing.Bitmap sourceImage, int intensity)
        {
            Bitmap returnImage = new Bitmap(sourceImage);
            
            intensity *= 2;
            Random random = new Random();
            int randomx, randomy, directionx, directiony;
            Color pixel;

            for (int i = 0; i < intensity; i++)
            {
                
                randomx = random.Next(0, sourceImage.Width);
                randomy = random.Next(0, sourceImage.Height);
                pixel = sourceImage.GetPixel(randomx, randomy);


                for (int j = 0; j < intensity; j++)
                {

                        directionx = random.Next(-1, 2);
                        directiony = random.Next(-1, 2);
                        randomx = randomx + directionx;
                        randomy = randomy + directiony;

                        if (randomx >= sourceImage.Width || randomx <= 0)
                        {
                            break;
                        }
                        if (randomy >= sourceImage.Height || randomy <= 0)
                        {
                            break;
                        }
                        //array2[(randomy * sourceImage.Width + randomx) * 3] = (byte)pixelR;
                        //array2[(randomy * sourceImage.Width + randomx) * 3 + 1] = (byte)pixelG;
                        //array2[(randomy * sourceImage.Width + randomx) * 3 + 2] = (byte)pixelB;
                        returnImage.SetPixel(randomx, randomy, pixel);
                }
            }

            //Marshal.Copy(array2, 0, adressreturn, arraySize);
            //returnImage.UnlockBits(returnImageData);
            //sourceImage.UnlockBits(sourceImageData);\
            return returnImage;
        }
    }
}